<template>
  <div class="condition-node">
    <div v-if="conditions && conditions.length">
      <div v-for="(c, i) in conditions" class="condition-item" :key="i">
        <p v-if="i !== 0">或</p>
        <p v-for="(item, j) in c" :key="j">
          <span v-if="j != 0">且</span>
          {{ item.label }} :
          <!-- 发起人 -->
          <template v-if="item.type === 3 && item.actioners">
            <a v-for="(a, k) in item.actioners" :key="a.id">
              {{ a.name }}
              <template v-if="k != item.actioners.length - 1">,</template>
            </a>
          </template>
          <!-- 选择 -->
          <template v-if="item.type === 2 && item.values">
            {{ item.values.join(',') }}
          </template>
          <!-- 数值 -->
          <template v-if="item.type === 1">
            <span v-if="item.numberType === 6">
              介于
              {{ item.minValue }} ~ {{ item.maxValue }}
            </span>
            <span v-else> {{ format(item.numberType) }} {{ item.value }} </span>
            <span v-if="item.unit">{{ item.unit }}</span>
          </template>
        </p>
      </div>
    </div>
    <div v-else class="text">请设置条件</div>
  </div>
</template>

<script setup lang="ts">
import { numberTypeArr } from '../../configs/dicts'
import type { Conditions } from '../../types'
defineProps({
  conditions: {
    type: Object as () => Conditions[],
    default: () => {
      return []
    }
  }
})
const format = (val: number) => {
  return numberTypeArr.find((el: any) => el.value === val)?.label
}
</script>
